//Nathan Popham
//4003-573-01: Procedural Shading
//Lab 3
//
//sphericalTexture.frag
// This shader uses the normal of the given object for spherical
// texture mapping. As the actual values of the coordinates don't matter, 
// except in relation to each other, this works well with a normalized surface normal.


varying vec3 N;

uniform sampler2D myTexture;

void main()
{
    float PI = 3.14159; 

    float phi = atan(N.x / N.z) + PI/2.0;
    float theta = acos(N.y);

    float u = phi / (2.0 * PI);
    float v = 1.0 - theta / PI;    

    vec3 color = vec3(texture2D(myTexture, vec2(u, v)));

	gl_FragColor = vec4(color, 1.0);
} 
